<?php

namespace mbilling\BillingBundle\Model;

use Doctrine\ORM\EntityManager;
use mbilling\BillingBundle\Entity\templates;


Class TemplatesModel
{
    protected $em;

    public function __construct(EntityManager $em)
    {
        $this->em = $em;
    }

    public function findAll()
    {
        $templates = $this->em->getRepository('BillingBundle:templates')->findAll();
        return $templates;
    }

    public function findByName($name)
    {
        $template = $this->em->getRepository('BillingBundle:templates')->findOneBy(array('name' => $name));
        if (isset($template))
            return $template;
        else
        {
            $template = new templates();
            $template->setBody('несуществующий шаблон');
            $tempalte->setTheme('ошибка');
            return $template;
        }
    }
    
    public function findByPK($template_id)
    {
        $template = $this->em->find('BillingBundle:templates', $template_id);
        return $template;
    }
    
    public function create($oEntity)
    {
        $this->em->persist($oEntity);
        $this->em->flush();
    }

    public function removeByPK($template_id)
    {
        $template= $this->em->find('BillingBundle:templates', $template_id);
        $this->em->remove($template);
        $this->em->flush();
    }
}
?>
